<template>
	<el-main>
		<el-card class="box-card" shadow="never">
			<div class="search-box">
				<el-form :inline="true" :model="searchForm" class="demo-form-inline" label-width="80px">
					<el-form-item label="是否使用">
						<el-select v-model="searchForm.status" placeholder="请选择" clearable>
							<el-option label="未使用" value="1"></el-option>
							<el-option label="已使用" value="2"></el-option>
							<el-option label="已过期" value="3"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="获得方式">
						<el-select v-model="searchForm.source" placeholder="请选择" clearable>
							<el-option label="自己领取" value="1"></el-option>
							<el-option label="商家赠送" value="2"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="领取人">
						<el-input v-model="searchForm.user_name" placeholder="" clearable></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div style="width:100%;height:0;border-bottom:#E4E7ED 1px dashed;margin-bottom: 10px"></div>
			<el-table
				:data="tableData"
				style="width: 100%;">
				<el-table-column
					prop="id"
					width="100px"
					label="ID">
				</el-table-column>
				<el-table-column
					prop="coupon_name"
					label="优惠券名称">
				</el-table-column>
				<el-table-column
					prop="user_name"
					label="获得人">
				</el-table-column>
				<el-table-column
					prop="coupon.amount"
					label="面值">
				</el-table-column>
				<el-table-column
					prop="coupon.threshold_amount"
					label="门槛金额">
				</el-table-column>
				<el-table-column
					prop="coupon.end_time"
					label="有效期">
				</el-table-column>
				<el-table-column
					label="获得方式">
					<template #default="scope">
						<el-tag v-if="scope.row.source == 1" type="success">自己领取</el-tag>
						<el-tag v-if="scope.row.source == 2" type="danger">商家赠送</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					prop="status"
					label="状态">
					<template #default="scope">
						<el-tag v-if="scope.row.status == 1" type="success">未使用</el-tag>
						<el-tag v-if="scope.row.status == 2" type="danger">已使用</el-tag>
						<el-tag v-if="scope.row.status == 3">已过期</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					prop="used_time"
					label="使用日期">
				</el-table-column>
			</el-table>
			<Pages :form="searchForm" :page-obj="page" @pageChange="handlePageChange" @pageJump="getList"></Pages>

		</el-card>
	</el-main>
</template>

<script>
import Pages from "@/components/pages/index.vue";

export default {
	components: {Pages},
	data() {
		return {
			searchForm: {
				type: 1,
				user_name: '',
				status: '',
				source: '',
				limit: 15,
				page: 1
			},
			page: {
				total: 0
			},
			tableData: []
		}
	},
	mounted() {
		this.getList()
	},
	methods: {
		// 获取列表
		async getList() {
			let res = await this.$API.coupon.receiveLog.get(this.searchForm)
			this.tableData = res.data.data
			this.page.total = res.data.total
		},
		// 搜索
		onSubmit() {
			this.searchForm.page = 1
			this.getList()
		},
		// 分页
		handlePageChange(page) {
			this.searchForm.page = page
			this.getList()
		}
	}
}
</script>

<style scoped>
.el-button--small {
	padding: 0 !important;
}
</style>
